#include <bits/stdc++.h>
using namespace std;

int n,m,l,V;
int d,v,a;
int ce[100005];
bool fi[1000005];

struct node{
	int start,now;
	bool flag;
};

node chao[100005];
vector <int> vis[1000005];

int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int q;
	cin >> q;
	while (q--){
		int cnt = 0,ans = 0,answ;
		cin >> n >> m >> l >> V;
		for (int i = 1;i <= n;i++){
			cin >> d >> v >> a;
			if (a == 0){
				if (v > V) chao[++cnt].start = d,chao[cnt].now = d,chao[cnt].flag = 2;
			}
			if (a < 0 && v <= V) continue;
			int tmp = (V - v * v) / (2 * a);
			tmp += d;
			if (tmp >= l && a > 0) continue;
			chao[++cnt].start = d;
			chao[cnt].now = tmp;
			if (a < 0) chao[cnt].flag = 0;
			else chao[cnt].flag = 1;
		}
		for (int i = 1;i <= m;i++){
			cin >> ce[i];
			bool flag = 0;
			int tmp = 0;
			for (int j = 1;j <= cnt;j++){
				if (chao[j].flag == 0){
					if (ce[i] >= chao[j].start && ce[i] < chao[j].now){
						flag = 1;
						vis[ce[i]].push_back(j);
					}
				}else if(chao[j].flag == 1){
					if (ce[i] > chao[j].now){
						flag = 1;
						vis[ce[i]].push_back(j);
					}
				}else{
					vis[ce[i]].push_back(j);
				}
			}
			if (flag) ans++;
		}
		
		for (int k = 1;k <= m;k++){
			bool flag = 0;
			int lg = 0,tmp = 0;
			for (int i = 1;i <= m;i++){
				if (lg < vis[ce[i]].size()){
					lg = vis[ce[i]].size();
					tmp = i;
				}
			}
			for (int i = 0;i < ce[tmp];i++){
				vis[i].pop_back();
				if (!fi[vis[ce[tmp]][i]]){
					fi[vis[ce[tmp]][i]] = 1;
					flag = 1;
				}
			}
			if (flag) answ++;
		}
		
		cout << ans << " " << answ << endl;
		for (int i = 1;i <= m;i++){
			for (int j = 0;j < vis[i].size();j++){
				vis[i].pop_back();
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}